package com.yoomiito.app.present.cicle

import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.XApi
import com.yoomiito.app.Constant
import com.yoomiito.app.base.AppConfig
import com.yoomiito.app.base.BaseLazyFragmentPresenter
import com.yoomiito.app.model.cicle.CicleRecommendInfo
import com.yoomiito.app.net.YmApi
import com.yoomiito.app.ui.fragment.cicle.PromotionalMaterialFragment
import com.yoomiito.app.utils.YMToast

class PromotionMaterialPresenter(appConfig:AppConfig) : BaseLazyFragmentPresenter<PromotionalMaterialFragment>(appConfig){

    fun getPromotionalMaterial(page:Int){
        YmApi.getYmService()
                .geGoodsRecommendData(Constant.COMMUNITY_TYPE_INVITE_MATERIAL, page, Constant.PAGE_SIZE)
                .compose(v.bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object : ApiSubscriber<CicleRecommendInfo>() {
                    override fun onSuccess(data: CicleRecommendInfo) {
                        v.setPublishMaterialData(data)
                    }

                    override fun onFail(error: ApiException) {
                        YMToast.showText("error")
                    }
                })
    }
}